(function(){ "use strict"; var KasikaContactUtility = { v :{ // }, getCookie : function (____t){ this.v.cookies = document.cookie.split(";"); this.v.cookie = null; this.v.cookies.map(function(____v){ if(____v.indexOf(____t) > -1) { this.v.cookie = ____v.split("=")[1]; } },this); return this.v.cookie; }, setSessionCookie : function(____t){ document.cookie = ____t + ";path=/;"; }, setPermanentCookie : function(____t){ this.v.expire = new Date(); this.v.expire.setTime(this.v.expire.getTime() + 1000 * 3600 * 24 * 365 * 10); document.cookie = ____t + ";path=/;expires=" + this.v.expire.toUTCString() + ";"; }, display : function(____t,____m){ if(____t === "info") console.info(____m); if(____t === "warn") console.warn(____m); if(____t === "error") console.error(____m); if(KasikaContactSetter.config.isDebug){ if(____t === "log") console.debug(____m); } }, httpRequest : function (){ this.v.callSettingXHR = new XMLHttpRequest(); this.v.callSettingXHR.open("POST",this.v.requestUrl,true); this.v.callSettingXHR.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); this.v.callSettingXHR = this.setHttpHandler(this.v.callSettingXHR); this.v.callSettingXHR.send(this.v.settingParams); }, setHttpHandler : function (){ this.v.callSettingXHR.addEventListener("progress", this.httpOnProgress); this.v.callSettingXHR.addEventListener("load", this.httpOLoad); this.v.callSettingXHR.addEventListener("error", this.httpOnError); this.v.callSettingXHR.addEventListener("abort", this.httpOnAbort); return this.v.callSettingXHR; }, httpOnProgress : function(____e){ KasikaContactUtility.display("log",{"KASIKA Ajax Inprogress":____e}) }, httpOnError : function(____e){ KasikaContactUtility.display("error",{"KASIKA Ajax Fatal Error":____e}) }, httpOnAbort : function(____e){ KasikaContactUtility.display("warn",{"KASIKA Ajax Aborted":____e}) }, httpOLoad : function(____e){ KasikaContactUtility.display("log",{"KASIKA Ajax Loaded":____e}) if(____e.target.readyState === 4 || ____e.target.status === 200){ try { KasikaContactUtility.v.json = JSON.parse(____e.target.responseText || null); if(KasikaContactUtility.v.json){ KasikaContactUtility.display("log",{"KASIKA Ajax Parsed JSON":____e}) KasikaContactUtility.v.callBack(KasikaContactUtility.v.json); }else{ KasikaContactUtility.display("warn",{"KASIKA Ajax Empty JSON":____e}) } } catch (____e) { KasikaContactUtility.display("warn",{"KASIKA Ajax JSON Parse Error":____e}) } }else{ KasikaContactUtility.display("warn",{"KASIKA Ajax Http Error":____e}) } } } var KasikaContactSetter = { props : { pid : "1D92ADF5AB53204D75C84B9502B4E658", identifierCookieName : "kasika_identifier_id", isDebugCookieName : "kasika_debug_enable", identifierId : null, cocoCidName : "_coco_cid", cocoCid : null, }, config : { domain : "https://pigeon.kasika.io/", checkPath : "new_contact_conversion/a.php", settingPath : "new_contact_conversion/b.php", registerPath : "new_contact_conversion/c.php", ajaxRegisterPath : "new_contact_conversion/d.php", trackingPath : "tracking_s/?pid=1D92ADF5AB53204D75C84B9502B4E658", isDebug : false, }, setting :{ // }, page :{ // }, v : { // }, start : function(){ KasikaContactUtility.display("log",{"KASIKA Initialize":KasikaContactSetter}) KasikaContactSetter.checkDebugMode(); KasikaContactSetter.props.identifierId = KasikaContactSetter.getIdentifierId(); KasikaContactUtility.setSessionCookie(KasikaContactSetter.props.identifierCookieName + "=" + KasikaContactSetter.props.identifierId); KasikaContactSetter.props.cocoCid = KasikaContactUtility.getCookie(KasikaContactSetter.props.cocoCidName); KasikaContactSetter.isExistSettingUrl(); }, checkDebugMode : function(){ this.v.isDebugCookieValue = KasikaContactUtility.getCookie(this.props.isDebugCookieName); if(this.v.isDebugCookieValue == 1){ this.config.isDebug = true; } }, getIdentifierId : function(){ KasikaContactUtility.v.tmpCookie = KasikaContactUtility.getCookie(this.props.identifierCookieName); return !KasikaContactUtility.v.tmpCookie ? this.createIdentifierId(this.props.identifierCookieName) : KasikaContactSetter.refreshIdentifierId(); }, createIdentifierId : function(){ return this.props.pid + "-" + new Date().getTime().toString(16) + Math.floor(1000 * Math.random()).toString(16) }, refreshIdentifierId : function(){ return this.props.pid + "-" + KasikaContactUtility.v.tmpCookie.split("-")[1]; }, removeIdentifierId : function(){ KasikaContactUtility.setSessionCookie(this.props.identifierCookieName + "=;path=/;expires=0"); }, setCurrentPageUrl : function(){ this.page.currentUrl = window.location.href; if(this.page.currentUrl === null){ KasikaContactUtility.display("warn",{"KASIKA Setter URL is Empty":this.page.currentUrl}) return; } KasikaContactUtility.display("log",{"KASIKA Setter Successful Get URL":this.page.currentUrl}); }, setCurrentPageHtml : function(){ this.page.html = document.getElementsByTagName('html')[0].innerHTML; if(this.page.html === null){ KasikaContactUtility.display("warn",{"KASIKA Setter HTML is Empty":this.page.html}) return; } KasikaContactUtility.display("log",{"KASIKA Setter Successful get of HTML":this.page.html}) }, isExistSettingUrl : function(){ this.setCurrentPageUrl(); KasikaContactUtility.v.settingParams = []; KasikaContactUtility.v.settingParams.push( "infomation=" + encodeURIComponent(JSON.stringify(this.props)) + "&" + "current_url=" + encodeURIComponent(JSON.stringify(this.page.currentUrl)) + "&" + "html=null" ); KasikaContactUtility.v.requestUrl = this.config.domain + this.config.checkPath; KasikaContactUtility.v.callBack = this.loadedCheckSetting; KasikaContactUtility.httpRequest(); }, loadedCheckSetting : function(____e){ if(____e && ____e.status === true){ KasikaContactUtility.display("log",{"KASIKA Setter Exist of Setting from URL":____e}); KasikaContactSetter.getSetting(); }else{ KasikaContactUtility.display("log",{"KASIKA Setter Not Exist of Setting from URL":____e}) } }, getSetting : function(){ this.setCurrentPageHtml(); KasikaContactUtility.v.settingParams = []; KasikaContactUtility.v.settingParams.push( "infomation=" + encodeURIComponent(JSON.stringify(this.props)) + "&" + "current_url=" + encodeURIComponent(JSON.stringify(this.page.currentUrl)) + "&" + "html=" + encodeURIComponent(this.page.html) ); KasikaContactUtility.v.requestUrl = this.config.domain + this.config.settingPath; KasikaContactUtility.v.callBack = this.loadedSetting; KasikaContactUtility.httpRequest(); }, loadedSetting : function(____e){ if(____e && ____e.status == true){ KasikaContactGetter.v = {}; KasikaContactSetter.v = {}; if(____e.cid && ____e.cid !== ""){ KasikaContactSetter.removeIdentifierId(); KasikaContactUtility.setPermanentCookie(KasikaContactSetter.props.cocoCidName + "=" + ____e.cid); KasikaContactUtility.display("info",{"KASIKA Setter Registed Customer":____e}); }else{ KasikaContactSetter.setting = ____e.setting; KasikaContactUtility.display("info",{"KASIKA Setter Initialize Finished":KasikaContactSetter}); KasikaContactGetter.run(); } }else if(____e && ____e.status == false){ KasikaContactUtility.display("debug",{"KASIKA Setter Error Response":____e}); }else{ KasikaContactUtility.display("warn",{"KASIKA Setter Ajax Empty Response":____e}); } }, }; var KasikaContactGetter = { props : { targetSelector : "input,select,textarea" }, v : { // }, run : function(){ if(KasikaContactSetter.setting.use_load && KasikaContactSetter.setting.use_load == 1){ this.get(); } this.addEvent(); }, get : function(){ KasikaContactGetter.v.forms = KasikaContactGetter.getForms(); if(KasikaContactGetter.v.forms.length === 0) return; KasikaContactGetter.v.form = []; KasikaContactGetter.v.index = 1; KasikaContactGetter.v.forms.map(function(____e){ this.v.target = [].slice.call(____e.querySelectorAll(this.props.targetSelector)); if(this.v.target.length > 0){ this.v.form[this.v.index] = []; this.getInput(this.v.index,____e); this.v.index++; } },KasikaContactGetter); KasikaContactUtility.display("debug",{"KASIKA Getter Got Forms & InputData" : KasikaContactGetter.v.form}); KasikaContactGetter.send(); KasikaContactGetter.addAjaxFromEvent(); }, addAjaxFromEvent : function(){ if(!KasikaContactSetter.setting.ajax) return; try { document.querySelector(KasikaContactSetter.setting.ajax).addEventListener("click",this.sendAjaxForm); } catch (____e) { KasikaContactUtility.display("warn",{"KASIKA Getter Ajax Selector Not Found Element" : KasikaContactSetter.setting.ajax}); } }, sendAjaxForm : function(){ KasikaContactUtility.v.settingParams = []; KasikaContactUtility.v.settingParams.push( "infomation=" + encodeURIComponent(JSON.stringify(KasikaContactSetter.props)) + "&" + "setting=" + encodeURIComponent(JSON.stringify(KasikaContactSetter.setting)) ); KasikaContactUtility.v.requestUrl = KasikaContactSetter.config.domain + KasikaContactSetter.config.ajaxRegisterPath; KasikaContactUtility.v.callBack = KasikaContactGetter.ajaxLoaded; KasikaContactUtility.httpRequest(); }, ajaxLoaded : function(____e){ if(____e.cid && ____e.cid !== ""){ try { KasikaContactGetter.v.scriptTag = document.createElement('script'); KasikaContactGetter.v.scriptTag.type = 'text/javascript'; KasikaContactGetter.v.scriptTag.src = KasikaContactSetter.config.domain + KasikaContactSetter.config.trackingPath;; document.getElementsByTagName('head')[0].appendChild(KasikaContactGetter.v.scriptTag); } catch (____ee) { KasikaContactUtility.display("warn",{"KASIKA Getter Failed Tracking Tag Append":____ee}); } KasikaContactUtility.setPermanentCookie(KasikaContactSetter.props.cocoCidName + "=" + ____e.cid); KasikaContactUtility.display("info",{"KASIKA Setter Registed Customer":____e}); }else if(____e.status === true){ KasikaContactUtility.display("debug",{"KASIKA Setter Empty Response":____e}); }else{ KasikaContactUtility.display("warn",{"KASIKA Setter Not Registed Customer":____e}); } }, addEvent : function(){ [].slice.call(document.querySelectorAll(KasikaContactGetter.props.targetSelector)).map(function(____e){ if(____e.type != "submit"){ ____e.addEventListener("blur",this.get); } },KasikaContactGetter) }, send : function(){ KasikaContactUtility.v.settingParams = []; KasikaContactUtility.v.settingParams.push( "infomation=" + encodeURIComponent(JSON.stringify(KasikaContactSetter.props)) + "&" + "setting=" + encodeURIComponent(JSON.stringify(KasikaContactSetter.setting)) + "&" + "data=" + encodeURIComponent(JSON.stringify(this.v.form)) ); KasikaContactUtility.v.requestUrl = KasikaContactSetter.config.domain + KasikaContactSetter.config.registerPath; KasikaContactUtility.v.callBack = KasikaContactGetter.loaded; KasikaContactUtility.httpRequest(); }, loaded : function(____e){ KasikaContactUtility.display("log",{"KASIKA Getter Ajax Loaded":____e}) if(____e && ____e.status === true){ KasikaContactUtility.display("log",{"KASIKA Getter Ajax Json Response" : ____e}); }else{ KasikaContactUtility.display("warn",{"KASIKA Getter Ajax Empty Response":____e}); } }, getForms : function(){ return [].slice.call(document.getElementsByTagName("form")) }, getInput : function(____i){ if(this.v.target.length === 0) return; this.v.target.map(function(____e){ this.v.obj = {}; if(____e.type === "radio" || ____e.type === "checkbox"){ if(____e.checked){ if(____e.name !== undefined && ____e.name !== ""){ this.v.obj = { name : ____e.name, value : ____e.value } }else if(____e.id !== undefined && ____e.id !== ""){ this.v.obj = { name : "#" + ____e.id, value : ____e.value } } } }else{ if(____e.name !== undefined && ____e.name !== ""){ this.v.obj = { name : ____e.name, value : ____e.value } }else if(____e.id !== undefined && ____e.id !== ""){ this.v.obj = { name : "#" + ____e.id, value : ____e.value } } } this.v.form[____i].push(this.v.obj); },KasikaContactGetter); } } try { if (document.readyState && document.readyState == 'loading') { if (document.addEventListener) { document.addEventListener('DOMContentLoaded', KasikaContactSetter.start); } else if (w.attachEvent) { document.attachEvent('DOMContentLoaded', KasikaContactSetter.start); } } else { KasikaContactSetter.start() } } catch (____e) { KasikaContactUtility.display("warn",{"KASIKA Fatal Error":____e}) } })();